package com.ruoyi.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.domain.entity.ForumPost;
import com.ruoyi.domain.entity.ForumPostDto;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 论坛Mapper接口
 * 
 * @author lsx
 * @date 2025-01-07
 */
@Mapper
public interface ForumPostMapper extends BaseMapper<ForumPost>
{
    /**
     * 查询论坛
     * 
     * @param id 论坛主键
     * @return 论坛
     */
    public ForumPostDto selectForumPostById(Integer id);

    /**
     * 查询论坛列表
     * 
     * @param forumPost 论坛
     * @return 论坛集合
     */
//    public List<ForumPost> selectForumPostList(ForumPost forumPost);

    /**
     * 新增论坛
     * 
     * @param forumPost 论坛
     * @return 结果
     */
    public boolean insertForumPost(ForumPost forumPost);

    /**
     * 修改论坛
     * 
     * @param forumPost 论坛
     * @return 结果
     */
    public int updateForumPost(ForumPost forumPost);

    /**
     * 删除论坛
     * 
     * @param id 论坛主键
     * @return 结果
     */
    public int deleteForumPostById(Integer id);

    /**
     * 批量删除论坛
     * 
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteForumPostByIds(Integer[] ids);

    List<ForumPost> getSearchPost(String keyword);

    void changePraise(@Param("id") Integer postId, @Param("praise") Integer likeCount);

    @Select("select count(1) from forum_like where user_id = #{userId} and forum_id = #{postId}")
    int getLikeCount(@Param("userId") Integer userId,@Param("postId") Integer postId);

    @Select("select user_id from forum_like where forum_id = #{forumId}")
    List<Integer> getLikeUserIds(@Param("forumId") Integer forumId);

    @Insert("insert into forum_like(user_id, forum_id) values(#{userId},#{postId}) ")
    void likePost(@Param("userId") Integer userId,@Param("postId") Integer postId);

    @Delete("delete from forum_like where user_id = #{userId} and forum_id = #{postId}")
    void cancelLikePost(@Param("userId") Integer userId,@Param("postId") Integer postId);

    List<ForumPostDto> getTopLikedStockPosts(@Param("stockId") Integer stockId,@Param("limit") Integer limit);
}
